/**   
 * @Title: GetServerTimeCommunicater.java 
 * @Package: com.esun.rabbit2.communicaters.lotteryinfo 
 * @Description: (获取服务器当前时间) 
 * @Author: Billy qigs@500wan.com   
 * @Date: 2011-8-26 上午10:14:13  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.lotteryinfo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Key;
import com.esun.config.Config;
import com.esun.model.ServerCurrentTimeInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: GetServerTimeCommunicater
 * @Description: (获取服务器当前时间)
 * @Author: Billy qigs@500wan.com
 * @Date: 2011-8-26 上午10:14:13
 */
public class GetServerTimeCommunicater extends ServerCommunicater {

	private String msgServer;

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String msgServer) {
		this.msgServer = msgServer;
	}

	/**
	 * @throws SAXException
	 * @throws ParserConfigurationException
	 * @throws IOException
	 * @throws ClientProtocolException
	 * @Title: isGetServerTimeSucceed
	 * @Description: TODO(获取服务器时间接口)
	 * @param: @return isSucceed
	 * @return: boolean 返回类型
	 * @throws
	 */
	public boolean isGetServerTimeSucceed() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {

		boolean isSucceed = false;
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(Config.PASER_MID, BussinessCode.MID_SERVER_TIME));

		super.getServerResponse(list, true);
		if (super.getState() == 100) {
			isSucceed = true;
		} else {
			isSucceed = false;
		}
		setMsgServer(super.getErrorMSG());
		return isSucceed;
	}

	public ServerCurrentTimeInfo getCurrentServerTime() {

		ServerCurrentTimeInfo timeInfo = new ServerCurrentTimeInfo();

		timeInfo.setServerTimeAll(super.getResult().get(Key.KEY_TIME));
		timeInfo.setServerDate(super.getResult().get(Key.KEY_YMD));
		timeInfo.setServerTime(super.getResult().get(Key.KEY_HMS));

		return timeInfo;

	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
